import { OfficeView } from '@/executor/open/office';
import { FileItemShare } from '@/ts/base/model';
import { IDirectory } from '@/ts/core';
import { getFileType } from '@/ts/core/thing/folder/FileFilter';
import { shareOpenLink } from '@/utils/tools';
import { Empty, Image } from 'antd';
import JolPlayer from 'jol-player';
import React from 'react';

interface Props {
  directory: IDirectory;
  file: FileItemShare;
  type?: string;
}

export default function FileOpen({ directory, file, type }: Props) {
  if (!type) {
    type = getFileType(file);
  }

  if (type == 'image') {
    return (
      <div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
        <Image src={shareOpenLink(file.shareLink)} style={{ width: '75%' }} />
      </div>
    );
  } else if (type == 'office') {
    return <OfficeView share={file} current={directory} />;
  } else if (type == 'video') {
    return (
      <JolPlayer
        option={{
          width: 830,
          height: 480,
          language: 'zh',
          pausePlacement: 'center',
          isShowScreenshot: false,
          poster: shareOpenLink(file.poster),
          videoSrc: shareOpenLink(file.shareLink),
          videoType: file.contentType === 'video/stream' ? 'hls' : 'h264',
        }}
      />
    );
  } else {
    return <Empty description="暂不支持预览该类型文件" />;
  }
}
